<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts';
import resize from './mixins/resize';

require('echarts/theme/macarons'); // echarts theme

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null
    };
  },
  watch: {

  },
  mounted() {

  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart(obj) {
      this.chart = echarts.init(this.$el, 'macarons');
      this.setOptions(obj);
    },
    setOptions(obj) {
      this.chart.setOption({
        xAxis: {
          data: obj.last7Days,
          boundaryGap: true,
          axisTick: {
            show: false
          }
        },
        grid: {
          left: 10,
          right: 10,
          bottom: 20,
          top: 30,
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          },
          padding: [5, 10]
        },
        yAxis: {
          axisTick: {
            show: false
          }
        },
        legend: {
          data: ['总人数', '主播人数', '团长人数', '分公司人数']
        },
        series: [
          {
            name: '总人数', itemStyle: {
              normal: {
                color: '#FF005A',
                lineStyle: {
                  color: '#FF005A',
                  width: 2
                }
              }
            },
            smooth: true,
            type: 'line',
            data: obj.dataList[0],
            animationDuration: 2800,
            animationEasing: 'cubicInOut'
          },
          {
            name: '主播人数',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#3888fa',
                lineStyle: {
                  color: '#3888fa',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: obj.dataList[1],
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          },
          {
            name: '团长人数',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#38FA79FF',
                lineStyle: {
                  color: '#38FA79FF',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: obj.dataList[2],
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          },
          {
            name: '分公司人数',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#C338FAFF',
                lineStyle: {
                  color: '#C338FAFF',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: obj.dataList[3],
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }
        ]
      });
    },
    info(obj) {
      this.initChart(obj);
    }
  }
};
</script>
